import Vue from 'vue'
import Router from 'vue-router'
// 获取组件
import Login from '@/components/Login'
import Home from '@/components/home/Home'
import Welcome from '@/components/home/Welcome'
import User from '@/components/user/User'
import Right from '@/components/power/Right'
import Role from '@/components/power/Role'
<<<<<<< HEAD
import Categories from '@/components/cate/Categories'
=======
import Cate from '@/components/cate/Cate'
>>>>>>> cate

Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/', redirect: '/home' },
    { path: '/login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/users', component: User },
        { path: '/rights', component: Right },
        { path: '/roles', component: Role },
<<<<<<< HEAD
        { path: '/categories', component: Categories }
=======
        { path: '/categories', component: Cate }
>>>>>>> cate
      ]
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') next()
  const token = window.sessionStorage.getItem('token')
  if (!token) return next('/login')
  next()
})

export default router
